package com.nanbei.a09;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @ClassDescription: Scope 失效问题
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/11/14 17:28
 */
@ComponentScan("com.nanbei.a09")
public class A09Application {

    private static final Logger log = LoggerFactory.getLogger(A09Application.class);

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(A09Application.class);
        E e = context.getBean(E.class);
        System.out.println("---------------- 通过 @Lazy 注解获取多例 ----------------");
        log.info("{}",e.getF1().getClass());
        log.info("{}",e.getF1());
        log.info("{}",e.getF1());
        log.info("{}",e.getF1());
        System.out.println("----------------  通过 @Scope(value = \"prototype\",proxyMode = ScopedProxyMode.TARGET_CLASS) ----------------");
        log.info("{}",e.getF2().getClass());
        log.info("{}",e.getF2());
        log.info("{}",e.getF2());
        log.info("{}",e.getF2());
        System.out.println("---------------- 通过工厂获取多例 ObjectFactory<F3>----------------");
        log.info("{}",e.getF3().getClass());
        log.info("{}",e.getF3());
        log.info("{}",e.getF3());
        log.info("{}",e.getF3());
        System.out.println("----------------  通过 applicationContext 获取多例 ----------------");
        log.info("{}",e.getF4().getClass());
        log.info("{}",e.getF4());
        log.info("{}",e.getF4());
        log.info("{}",e.getF4());
        context.close();
    }
}
